
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPubSub;

import java.util.concurrent.TimeUnit;

public class JedisDemo {
    static Jedis jedis;

    @BeforeAll
    public static void init(){
        jedis=new Jedis("192.168.150.77",6379);
    }
    @Test
    void t0(){
        String res=jedis.ping();
        System.out.println(res);
        jedis.flushAll();
    }
    @Test
    void t1() throws Exception{
        jedis.set("name","jie");
        jedis.expire("name",3);
        TimeUnit.SECONDS.sleep(4);
        System.out.println(jedis.get("name"));
    }
    @Test
    void t2() throws Exception{
        jedis.subscribe(new JedisPubSub() {
            @Override
            public void onMessage(String channel, String message) {
                System.out.println(channel+message);
            }
        },"X");
        TimeUnit.SECONDS.sleep(10);
    }
    @Test
    void t3(){
        jedis.publish("X","你好");
    }
}
